package com.vnp.cooking.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class UsernameValidator {
	private Pattern pattern;
	private Matcher matcher;

	private static final String USERNAME_PATTERN = "^[a-z0-9_-]{3,15}$";

	public UsernameValidator() {
		pattern = Pattern.compile(USERNAME_PATTERN);
	}

	/**
	 * Validate username with regular expression
	 * 
	 * @param username
	 *            username for validation
	 * @return true valid username, false invalid username
	 */
	public static boolean validate(final String username) {

        CharSequence inputStr = username.replaceAll("\\D+.[/,:<>!~@#$%^&()+=?()\"|!\\[#$-]", "");
        Pattern pattern = Pattern.compile(USERNAME_PATTERN);
        Matcher matcher = pattern.matcher(inputStr);
        if(matcher.matches()){
            return true;
        } else {
            return false;
        }

	}
}
